home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Resources / Online / Term / Extras / Source / gtlayout-source.lha / LTP_Rescale.c < prev    next >
C/C++ Source or Header  |  1996-03-18  |  3KB  |  136 lines

  1. /*
  2. **    GadTools layout toolkit
  3. **
  4. **    Copyright © 1993-1996 by Olaf `Olsen' Barthel
  5. **        Freely distributable.
  6. **
  7. **    :ts=4
  8. */
  9.  
  10. #ifndef _GTLAYOUT_GLOBAL_H
  11. #include "gtlayout_global.h"
  12. #endif
  13.  
  14. VOID
  15. LTP_ResetListViewTextAttrs(ObjectNode *group)
  16. {
  17.     ObjectNode *node;
  18.  
  19.     SCANGROUP(group,node)
  20.     {
  21.         if(node->Type == GROUP_KIND)
  22.             LTP_ResetListViewTextAttrs(node);
  23.         else
  24.         {
  25.             if(node->Type == LISTVIEW_KIND && node->Special.List.TextAttr)
  26.                 node->Special.List.TextAttr = NULL;
  27.         }
  28.     }
  29. }
  30.  
  31. VOID
  32. LTP_Rescale(LayoutHandle *handle,BOOL trimWidth,BOOL trimHeight)
  33. {
  34.     STATIC struct TextAttr topazAttr =
  35.     {
  36.         "topaz.font",
  37.         8,
  38.         FS_NORMAL,
  39.         FPF_ROMFONT | FPF_DESIGNED
  40.     };
  41.  
  42.     if(handle->TextAttr != &topazAttr && (Stricmp(handle->TextAttr->ta_Name,"topaz.font") || handle->TextAttr->ta_YSize != 8))
  43.     {
  44.         struct RastPort *rp;
  45.  
  46.         LONG    oldWidth;
  47.         LONG    oldHeight;
  48.         LONG    count;
  49.         LONG    i;
  50.         LONG    total;
  51.         LONG    width;
  52.         UBYTE    glyph;
  53.         LONG    oldStyle;
  54.  
  55.         rp = &handle->RPort;
  56.  
  57.         oldStyle    = rp->AlgoStyle;
  58.         oldWidth    = handle->GlyphWidth;
  59.         oldHeight    = handle->GlyphHeight;
  60.  
  61.         LTP_ResetListViewTextAttrs(handle->TopGroup);
  62.  
  63.         if(handle->CloseFont)
  64.             CloseFont(rp->Font);
  65.  
  66.         /*
  67.          * Note from Martin:
  68.          * GfxBase->DefaultFont is guaranteed not to ever be removed from
  69.          * memory, so we use that fact...
  70.          *
  71.          * I wasn't comfortable with that assumption, so I returned to
  72.          * the old way of doing it in v26.17
  73.          */
  74.  
  75.         Forbid();
  76.  
  77.         LTP_GetDefaultFont((struct TTextAttr *)(handle->TextAttr = &handle->CopyTextAttr));
  78.  
  79.         LTP_SetFont(handle,LTP_OpenFont(handle->TextAttr));
  80.  
  81.         handle->CloseFont = TRUE;
  82.  
  83.         Permit();
  84.  
  85.         SetSoftStyle(rp,FSF_BOLD | FSF_UNDERLINED,FSF_BOLD | FSF_UNDERLINED);
  86.  
  87.         FOREVER
  88.         {
  89.             count = total = 0;
  90.  
  91.             for(i = 32 ; i < 256 ; i++)
  92.             {
  93.                 if(i == 128)
  94.                     i = 160;
  95.  
  96.                 glyph = i;
  97.  
  98.                 width = TextLength(rp,&glyph,1);
  99.  
  100.                 if(width > 0 && width < 32768)
  101.                 {
  102.                     total += width;
  103.                     count++;
  104.                 }
  105.             }
  106.  
  107.             if((trimWidth && (total / count >= oldWidth)) || (trimHeight && (rp->TxHeight >= oldHeight)))
  108.             {
  109.                 if(handle->TextAttr == &topazAttr || (!Stricmp(handle->TextAttr->ta_Name,"topaz.font") && handle->TextAttr->ta_YSize == 8))
  110.                     break;
  111.                 else
  112.                 {
  113.                     if(handle->CloseFont)
  114.                         CloseFont(rp->Font);
  115.  
  116.                     LTP_SetFont(handle,OpenFont(handle->TextAttr = &topazAttr));
  117.  
  118.                     handle->CloseFont = TRUE;
  119.                 }
  120.             }
  121.             else
  122.             {
  123.                 handle->Rescaled = TRUE;
  124.  
  125.                 LTP_ResetGroups(handle->TopGroup);
  126.  
  127.                 LTP_GlyphSetup(handle,handle->TextAttr);
  128.  
  129.                 break;
  130.             }
  131.         }
  132.  
  133.         SetSoftStyle(rp,oldStyle,FSF_BOLD | FSF_UNDERLINED);
  134.     }
  135. }
  136.